package to52.android.screens;

import to52.android.adapters.PatientAdapter;
import to52.android.database.RetreiveData;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import fr.utbm.Patient;


public class PatientList extends ListActivity {

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("Liste des patients");
        //DatabaseModel dm = DatabaseSimulator.getInstance();
        RetreiveData rd = new RetreiveData(this);
        
        if (rd.getPatients() == null)
        	Log.d("mess", "Patient list is null");
        else
        	Log.d("mess", "PatientList screen : " + rd.getPatients().size());
        setListAdapter(new PatientAdapter(this, rd.getPatients()));
        rd.close();
    }


	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		final Patient p = (Patient)getListAdapter().getItem(position);
		
		Intent i = new Intent();
		i.setClass(getApplicationContext(), PatientDetailsList.class);
		i.putExtra("current_patient_id", p.getId());
		startActivity(i);
	}
	
}
